package com.szly.phm.common.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.Getter;

/**
 * phm
 *
 * @author: git.jas0nch
 * date: 2021-11-14
 */

@Getter
public enum PHMEnum {
    // enum value
    DEFAULT(2,"手动"),
    MANUAL(0,"手动"),
    AUTO(1,"自动");
    //
    @EnumValue
    private int faultResource;
    @JsonValue
    private String message;

    PHMEnum(int faultResource, String message) {
        this.faultResource = faultResource;
        this.message = message;
    }

    /**
     * 根据代码获取对应的message
     *
     * @auther: zq
     */
    public static String name(int code) {
        PHMEnum[] values = PHMEnum.values();
        for (PHMEnum value : values) {
            if (value.getFaultResource()==code) {
                return value.getMessage();
            }
        }
        return "手动";
    }

    /**
     * 根据代码获取枚举
     *
     * @auther: zq
     */

    public static PHMEnum getEnumByCode(int code) {
        for (PHMEnum oaEnum : PHMEnum.values()) {
            if (oaEnum.getFaultResource()==code) {
                return oaEnum;
            }
        }
        return null;
    }
}
